﻿package net.wangit.dev.wizard;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.context.ActionContextHelper;
import net.wangit.framework.config.BeanFactory;
import net.wangit.support.UnitInterceptor;
import net.wangit.view.Suite;

public class WizardUI implements UnitInterceptor {

	protected static final String SESSION_KEY = "net.wangit.dev.wizard.SC";
	private static final String DEFAULT_SUITE_ID = "11";

	public WizardUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String suiteId = ActionContextHelper
				.getRequest2Session(ac, "wizard.suite", WizardUI.SESSION_KEY,
						WizardUI.DEFAULT_SUITE_ID);
		Suite suite = BeanFactory.getSuite(suiteId);
		unit.getElement("case").setObject(suite.getCaseUnit(ac));
		unit.getElement("suite").setDefaultValue(suiteId);
		unit.getElement("unit").setObject(suite.getUnit(ac));
		return unit.write(ac);
	}
}
